import { Get, Post, Param, Delete, Body } from '@nestjs/common';
import { TasksService } from './tasks.service';
import { CreateTasksDto } from './dto/create-tasks.dto';
import { ApiOperation } from '@nestjs/swagger';
import { GetTasksFilterDto } from './dto/get-tasks-filter.dto';
import { UpdateTasksStatusDto } from './dto/update-tasks-status.dto';
import { Task } from './entities/task.entity';
import { GetUser } from '../../system/auth/get-user.decorator';
import { User } from '../../system/user/entities/user.entity';
import { Logger } from '@nestjs/common';
import { WitAdmin } from '../../system/auth/wit.admin';

@WitAdmin('tasks')
export class TasksController {
  private logger = new Logger('TasksController', { timestamp: true });
  constructor(private tasksService: TasksService) {}
  @Post('/getTasksList')
  @ApiOperation({
    summary: '获取所有数据',
  })
  getTasks(
    @Body() filterDto: GetTasksFilterDto,
    @GetUser() user: User,
  ): Promise<Task[]> {
    this.logger.verbose(
      `User "${user.username}" retreving all Task. Filters: ${JSON.stringify(
        filterDto,
      )}`,
    );
    return this.tasksService.getTasksList(filterDto, user);
  }
  @Get('/getTasksById/:id')
  @ApiOperation({
    summary: '获取指定ID数据',
  })
  getTaskById(@Param('id') id: string, @GetUser() user: User): Promise<Task> {
    return this.tasksService.getTasksById(id, user);
  }
  @Post('/addTasks')
  @ApiOperation({
    summary: '添加数据',
  })
  createTasks(
    @Body() createTasksDto: CreateTasksDto,
    @GetUser() user: User,
  ): Promise<Task> {
    this.logger.verbose(
      `User "${user.username}" createing a new task. Data: ${JSON.stringify(
        createTasksDto,
      )}`,
    );
    return this.tasksService.createTasks(createTasksDto, user);
  }

  @Delete('/deleteTasks/:id')
  @ApiOperation({
    summary: '删除数据',
  })
  deleteTasks(@Param('id') id: string, @GetUser() user: User): Promise<void> {
    return this.tasksService.deleteTasks(id, user);
  }
  @Post('/updateTasks')
  @ApiOperation({
    summary: '更新数据',
  })
  updateTasks(
    @Body() updateTasksStatusDto: UpdateTasksStatusDto,
    @GetUser() user: User,
  ): Promise<Task> {
    return this.tasksService.updateTasksStatus(updateTasksStatusDto, user);
  }
}
